package game.editer.history;

using Reflect;

/**
 * 修改属性
 */
class ChangeAttr extends HistoryAction {
	public var object:Dynamic;

	public var oldValue:Dynamic;

	public var newValue:Dynamic;

	public function new(object:Dynamic, oldValue:Dynamic, newValue:Dynamic) {
		super();
		this.object = object;
		this.oldValue = oldValue;
		this.newValue = newValue;
	}

	override function undo() {
		var hasOrigin = false;
		for (key in this.oldValue.fields()) {
			if (key.indexOf("origin") == 0) {
				hasOrigin = true;
			}
			this.object.setProperty(key, this.oldValue.getProperty(key));
		}
		if (hasOrigin) {
			EditerStage.timeline.currentActionData.updateActionData();
		}
		EditerStage.timeline.updateTimelineData(true);
		EditerStage.objectSelect.update();
	}
}
